package day03;

import org.junit.Test;

import java.util.Comparator;
import java.util.TreeMap;

public class TreeMapDemo {
    public static void main(String[] args) {
        TreeMap<Student,String> treeMap = new TreeMap<>();
        treeMap.put(new Student("Mike",21),"非洲");
        treeMap.put(new Student("Jack",20),"美洲");
        treeMap.put(new Student("Rose",18),"非洲");
        treeMap.put(new Student("jerry",22),"大洋洲");

        treeMap.forEach((k,v)->{
            //升序
            System.out.println(k+":"+v);
        });
        System.out.println("------------------1-------------");

//        test2();
//        System.out.println("------------------2-------------");

    }
    //单元测试
    @Test
    public void test2(){
        TreeMap<Student,String> treeMap = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                //降序
                return o2.getAge()-o1.getAge();
            }
        });
        treeMap.put(new Student("Mike",21),"非洲");
        treeMap.put(new Student("Jack",20),"美洲");
        treeMap.put(new Student("Rose",18),"非洲");
        treeMap.put(new Student("jerry",22),"大洋洲");

        treeMap.forEach((k,v)->{
            System.out.println(k+":"+v);
        });
    }
}
